package com.dongdongshop.data;

/**
 * @Description
 * @ClassName HobbyEnum
 * @Author RC
 * @date 2020.12.10 00:57
 */
public enum  HobbyEnum {
    CHOUYAN(1,"抽烟"), HEJIU(2,"喝酒"), TANGTOU(3,"烫头");
    private Integer index;
    private String name;

    public static HobbyEnum getHobbyNameByIndex(Integer index){
        HobbyEnum[] values = HobbyEnum.values();
        for (HobbyEnum value : values) {
            if(value.getIndex()==index){
                return value;
            }
        }
        return null;
    }
    public static HobbyEnum getHobbyIndexByName(String name){
        HobbyEnum[] values = HobbyEnum.values();
        for (HobbyEnum value : values) {
            if(value.getName().equals(name)){
                return value;
            }
        }
        return null;
    }

    HobbyEnum(Integer index, String name) {
        this.index = index;
        this.name = name;
    }

    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    public static void main(String[] args){
        Integer i =2;
        if(i ==1){
            System.out.println("抽烟");
        }
        HobbyEnum hobbyNameByIndex = HobbyEnum.getHobbyNameByIndex(i);
        System.out.println(hobbyNameByIndex.getName());

        HobbyEnum hobby = HobbyEnum.getHobbyIndexByName("喝酒");
        System.out.println(hobby.getIndex());
    }
}
